<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getRow(rowIndex) {
            let arr = [[1]]
            if (rowIndex) {
                for (let i = 1; i < rowIndex; i++) {
                    arr[i] = []
                    for (let j = 0; j < i + 1; j++) {
                        // arr当前项的数组 = arr[1 -1][0] + arr[1-1][0-1]
                        // arr[1][0] = arr[0][0] + arr[0][-1] = 1 + 0    ----> 0
                        // arr[1][1] = arr[0][1] + arr[0][0] = 0 + 1     ----> 1 [1,1]
                        arr[i][j] = (arr[i - 1][j] || 0) + (arr[i - 1][j - 1] || 0)
                    }

                }
                return arr
            } else {
                return []
            }


        };
        console.log(getRow(5));
    </script>
</body>

</html>